package com.iretailer.report.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iretailer.report.mapper.HolidaysMapper;
import com.iretailer.report.model.Holidays;
import com.iretailer.report.util.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Bennie
 * @Auther: xjw
 * @Date: 2019/1/24 11:34
 * @Description:
 */
@Service
public class HolidayService extends ServiceImpl<HolidaysMapper, Holidays> {

    private final HolidaysMapper holidaysMapper;

    public HolidayService(HolidaysMapper holidaysMapper) {
        this.holidaysMapper = holidaysMapper;
    }

    public List<Holidays> selectAllHolidays() {
        return holidaysMapper.selectList(new QueryWrapper<Holidays>().orderByAsc("Holiday"));
    }

    /**
     * 新增
     * 更新
     */
    @Override
    public boolean saveOrUpdate(Holidays holidays) {
        if (StringUtil.notEmpty(holidays.getId())) {
            holidaysMapper.updateById(holidays);
            return true;
        } else {
            holidaysMapper.insert(holidays);
            return true;
        }
    }
}
